package com.liip.platform.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.liip.platform.common.ReturnT;
import com.liip.platform.entity.User;
import com.liip.platform.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @description 用户信息
 * @author 罗林
 * @date 2020-03-25 15:48:09
 */
@Api(tags = { "用户操作接口" })
@RestController
@RequestMapping(value = "/SysUser")
public class UserController {
	@Resource
    private UserService userService;

    /**
    * 新增
    * @author 罗林
    * @date 2020/03/25
    **/
	//@OperLog(operModul="新增用户",operType="insert",operDesc ="新增注册")
	@ApiOperation(value = "新增用户信息", notes = "新增用户信息")
	@ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "用户id", required = false),
                @ApiImplicitParam(name = "loginName", value = "登录名", required = true),
                @ApiImplicitParam(name = "loginPassword", value = "密码", required = true),
                @ApiImplicitParam(name = "realName", value = "真实姓名", required = false),
                @ApiImplicitParam(name = "positionId", value = "职位id", required = false),
                @ApiImplicitParam(name = "positionName", value = "职位名称", required = false),
                @ApiImplicitParam(name = "branchId", value = "部门id", required = false),
                @ApiImplicitParam(name = "branchName", value = "部门名称", required = false),
                @ApiImplicitParam(name = "mobile", value = "手机号", required = false),
                @ApiImplicitParam(name = "isEnabled", value = "是否启用", required = false),
                @ApiImplicitParam(name = "createdat", value = "创建时间", required = false),
                @ApiImplicitParam(name = "updatedat", value = "更新时间", required = false)
    })
    @RequestMapping("/insert")
    public ReturnT<String> insert(User user){
        return userService.insert(user);
    }

    /**
    * 刪除
    * @author 罗林
    * @date 2020/03/25
    **/
	@ApiOperation(value = "刪除用户信息", notes = "刪除用户信息")
	@ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "用户id", required = true)
    })
    @RequestMapping("/delete")
    public ReturnT<String> delete(int id){
        return userService.delete(id);
    }

    /**
    * 更新
    * @author 罗林
    * @date 2020/03/25
    **/
	@ApiOperation(value = "更新用户信息", notes = "更新用户信息")
	@ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "用户id", required = true),
                @ApiImplicitParam(name = "loginName", value = "登录名", required = false),
                @ApiImplicitParam(name = "loginPassword", value = "密码", required = false),
                @ApiImplicitParam(name = "realName", value = "真实姓名", required = false),
                @ApiImplicitParam(name = "positionId", value = "职位id", required = false),
                @ApiImplicitParam(name = "positionName", value = "职位名称", required = false),
                @ApiImplicitParam(name = "branchId", value = "部门id", required = false),
                @ApiImplicitParam(name = "branchName", value = "部门名称", required = false),
                @ApiImplicitParam(name = "mobile", value = "手机号", required = false),
                @ApiImplicitParam(name = "isEnabled", value = "是否启用", required = false),
                @ApiImplicitParam(name = "createdat", value = "创建时间", required = false),
                @ApiImplicitParam(name = "updatedat", value = "更新时间", required = false)
    })
    @RequestMapping("/update")
    public ReturnT<String> update(User user){
        return userService.update(user);
    }

    /**
    * 查询 根据主键 id 查询
    * @author 罗林
    * @date 2020/03/25
    **/
	@ApiOperation(value = "根据主键 id 查询用户信息", notes = "根据主键 id 查询用户信息")
	@ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "用户id", required = true)
    })
    @RequestMapping("/load")
    public User load(int id){
        return userService.load(id);
    }

    /**
    * 查询 分页查询
    * @author 罗林
    * @date 2020/03/25
    **/
	@ApiOperation(value = "分页查询 用户信息", notes = "分页查询 用户信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "offset", value = "页码", required = true ),
                @ApiImplicitParam(name = "pagesize", value = "数量", required = true )
    })
    @RequestMapping("/pageList")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int offset,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return userService.pageList(offset, pagesize);
    }
}
